<?php

require_once './application/entity/common/attenteReponse.php';
require_once './application/models/Objets/Utilisateur.php';
require_once './library/XML/xmlToObjArray.php';

///
/// Classe de base pour le coeur de traitement
///
class CoreBase
{

    protected $_controller;
    protected $_session;
    private $_identity;
    private $_ip;
    private $_config;
    private $_configPath;
    private $_obj;

// Constructeur
    public function __construct(&$controller)
    {
        $this->_controller = $controller;
    }

    public function MiseEnAttenteReponse($value, $return, $donnee)
    {
        $attente = new attenteReponse();
        $attente->value = $value;
        $attente->functionReturn = $return;
        $attente->donnees = $donnee;
        echo Zend_Json_Encoder::encode($attente);
    }

//recupere les identifiant en base
    public function listIdentityFilter()
    {
        $this->_obj = new ObjectUtilisateur();
        $this->_session = new Zend_Session_Namespace('session');
        if (isset($this->_session->idClient))
        {
            $this->_identity = $this->_obj->InfoConfigNetwork($this->_session->idClient);
            return $this->_identity;
        }
        else
            return false;
    }

//recupere les username en base
    public function getUsernameBase($name)
    {
        $this->_identity = $name;
        $this->_obj = new TableConfigNetwork();
        $arr = $this->_obj->getConfigNetworkName($this->_identity);
        $this->_identity = null;
        foreach ($arr as $key)
            $this->_identity .= "{" . $key['LoginNetwork'] . "," . $key['PassNetwork'] . "}";
        return $this->_identity;
    }

    //Permet d obtenir xml en tableau
    public function parseResp($xml)
    {
        $this->_obj = new xmlToObjArray();
        $xml = $this->_obj->parse_xml_data($xml, false);
        $xml = $xml[0]['PARAM'][0];
        return $xml;
    }

//Parse les ip pour la sonde
    public function parseArrayIp($ip)
    {
        $this->_ip = $ip;
        $this->_ip = str_replace("[{", "", $this->_ip);
        $this->_ip = str_replace("}]", "", $this->_ip);
        return $this->_ip;
    }

    //Recupere les model et type dans le ini
    public function listParamFilter()
    {
        $arr = array();
        $this->_configPath = './application/configuration/service/config.ini';
        $this->_config = new Zend_Config_Ini($this->_configPath, 'param');
        if (stristr($this->_config->model, ",") == true)
            $arr['model'] = explode(",", $this->_config->model);
        else
            $arr['model'] = array($this->_config->model);
        if (stristr($this->_config->type, ",") == true)
            $arr['type'] = explode(",", $this->_config->type);
        else
            $arr['type'] = array($this->_config->type);
        if (stristr($this->_config->protocol, ",") == true)
            $arr['protocol'] = explode(",", $this->_config->protocol);
        else
            $arr['protocol'] = array($this->_config->protocol);
        return $arr;
    }

}
